<?php

namespace WsdServer\Lib\Session;

use SessionHandlerInterface;

class RedisSessionHandler implements SessionHandlerInterface
{
    /**
     * @var int session 过期时间
     */
    protected $minutes;


    public function __construct($minutes)
    {
        $this->cache = get_instance()->getRedis();
        $this->minutes = $minutes;
    }

    public function open($savePath, $sessionName)
    {
        return true;
    }

    public function close()
    {
        return true;
    }
    
    public function destroy($sessionId)
    {

    }
    
    public function gc($maxlifetime)
    {
        return true;
    }

    public function read($sessionId)
    {
        return $this->cache->get($sessionId);
    }
    
    public function write($sessionId, $data)
    {
        return $this->cache->setex($sessionId, $this->minutes, $data);
    }

}